// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/*!
 * @file twoString.cpp
 * This source file contains the definition of the described types in the IDL file.
 *
 * This file was generated by the tool gen.
 */

#ifdef _WIN32
// Remove linker warning LNK4221 on Visual Studio
namespace {
char dummy;
}  // namespace
#endif  // _WIN32

#include "twoString.h"
#include "twoStringTypeObject.h"
#include <fastcdr/Cdr.h>

#include <fastcdr/exceptions/BadParamException.h>
using namespace eprosima::fastcdr::exception;

#include <utility>

TestString::TestString()
{
    // m_str1 com.eprosima.idl.parser.typecode.StringTypeCode@548e7350
    m_str1 ="";
    // m_str2 com.eprosima.idl.parser.typecode.StringTypeCode@1a968a59
    m_str2 ="";

    // Just to register all known types
    registertwoStringTypes();
}

TestString::~TestString()
{


}

TestString::TestString(
        const TestString& x)
{
    m_str1 = x.m_str1;
    m_str2 = x.m_str2;
}

TestString::TestString(
        TestString&& x)
{
    m_str1 = std::move(x.m_str1);
    m_str2 = std::move(x.m_str2);
}

TestString& TestString::operator =(
        const TestString& x)
{

    m_str1 = x.m_str1;
    m_str2 = x.m_str2;

    return *this;
}

TestString& TestString::operator =(
        TestString&& x)
{

    m_str1 = std::move(x.m_str1);
    m_str2 = std::move(x.m_str2);

    return *this;
}

size_t TestString::getMaxCdrSerializedSize(
        size_t current_alignment)
{
    size_t initial_alignment = current_alignment;


    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;

    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + 255 + 1;       

    //current_alignment += 10240 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);       

    /*
    TestString* ts = (TestString*)data;

    if (ts->m_str1.size() > 500) {
        current_alignment += ts->m_str1.size() + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
    }
    if (ts->m_str2.size() > 500) {
        current_alignment += ts->m_str2.size() + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
    }    */

    return current_alignment - initial_alignment;
}

size_t TestString::getCdrSerializedSize(
        const TestString& data,
        size_t current_alignment)
{
    (void)data;
    size_t initial_alignment = current_alignment;


    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.str1().size() + 1;

    current_alignment += 4 + eprosima::fastcdr::Cdr::alignment(current_alignment, 4) + data.str2().size() + 1;
    
    /*if (data.str1().size() > 0) {
        current_alignment += (data.str1().size() * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
    }

    if (data.str2().size() > 0) {
        current_alignment += (data.str2().size() * 1) + eprosima::fastcdr::Cdr::alignment(current_alignment, 4);
    }*/

    return current_alignment - initial_alignment;
}

void TestString::serialize(
        eprosima::fastcdr::Cdr& scdr) const
{

    scdr << m_str1;
    scdr << m_str2;

}

void TestString::deserialize(
        eprosima::fastcdr::Cdr& dcdr)
{

    dcdr >> m_str1;
    dcdr >> m_str2;
}

/*!
 * @brief This function copies the value in member str1
 * @param _str1 New value to be copied in member str1
 */
void TestString::str1(
        const std::string& _str1)
{
    m_str1 = _str1;
}

/*!
 * @brief This function moves the value in member str1
 * @param _str1 New value to be moved in member str1
 */
void TestString::str1(
        std::string&& _str1)
{
    m_str1 = std::move(_str1);
}

/*!
 * @brief This function returns a constant reference to member str1
 * @return Constant reference to member str1
 */
const std::string& TestString::str1() const
{
    return m_str1;
}

/*!
 * @brief This function returns a reference to member str1
 * @return Reference to member str1
 */
std::string& TestString::str1()
{
    return m_str1;
}
/*!
 * @brief This function copies the value in member str2
 * @param _str2 New value to be copied in member str2
 */
void TestString::str2(
        const std::string& _str2)
{
    m_str2 = _str2;
}

/*!
 * @brief This function moves the value in member str2
 * @param _str2 New value to be moved in member str2
 */
void TestString::str2(
        std::string&& _str2)
{
    m_str2 = std::move(_str2);
}

/*!
 * @brief This function returns a constant reference to member str2
 * @return Constant reference to member str2
 */
const std::string& TestString::str2() const
{
    return m_str2;
}

/*!
 * @brief This function returns a reference to member str2
 * @return Reference to member str2
 */
std::string& TestString::str2()
{
    return m_str2;
}

size_t TestString::getKeyMaxCdrSerializedSize(
        size_t current_alignment)
{
    size_t current_align = current_alignment;





    return current_align;
}

bool TestString::isKeyDefined()
{
    return false;
}

void TestString::serializeKey(
        eprosima::fastcdr::Cdr& scdr) const
{
    (void) scdr;
      
}
